using System;
using System.Collections.Generic;
using System.Data;

using Elev.Core.DAL;

namespace Elev.Core
{
    public class StudentsFactory
    {
        public List<Student> GetStudents()
        {
            StudentInternal s = new StudentInternal();
            DataTable dt = s.GetStudents();
            List<Student> list = new List<Student>();
            
            if (dt.Rows.Count > 0)
                foreach (DataRow dr in dt.Rows)
                    list.Add(new Student(dr));

            return list;
        }

        public Student GetStudent(int ID)
        {
            StudentInternal s = new StudentInternal();
            DataTable dt = s.GetStudent(ID);

            if (dt.Rows.Count == 0)
                throw new ArgumentException(string.Format("There is no student for the id '{0}'", ID));

            if (dt.Rows.Count > 1)
                throw new ArgumentException(string.Format("There is more than one student for the id '{0}'", ID));

            return new Student(dt.Rows[0]);
        }
    }
}
